/*
 * Property.c
 *
 *  Created on: 23.09.2011
 *      Author: sili
 */

#include "Property.h"

static log4cxx::LoggerPtr logger(log4cxx::Logger::getLogger("at.sili.aalsystem.model.Property"));

void Property::setBasic(const char * _name, PROP_TYPE _type){
	this->id = Tools::getNewGlobalId();
	this->name.clear();
	this->name.append(_name);
	this->type = _type;
	this->intValue = 0;
	this->doubleValue = 0.0;
	this->stringValue.clear();
}

Property::Property(const char * _name, PROP_TYPE _type, int _defaultIntValue, vector<string> * _enumerationItems){
	setBasic(_name, _type);
	if(_enumerationItems){
		vector<string>::iterator it;
		for (it=_enumerationItems->begin(); it!=_enumerationItems->end(); it++ ){
			string entry = (*it);
			enumerationItems.push_back(entry.c_str());
		}
	}
	intValue = _defaultIntValue;
	defaultItValue = _defaultIntValue;
	AAL_DEBUG(logger, "Creating new INTEGER property %s id %d values %d, %4.2f, %s",this->name.c_str(),this->id, this->getIntValue(), this->doubleValue, this->stringValue.c_str());
}

Property::Property(const char * _name, PROP_TYPE _type, double _defaultDoubleValue, vector<string> * _enumerationItems){
	setBasic(_name, _type);
	if(_enumerationItems){
		vector<string>::iterator it;
		for (it=_enumerationItems->begin(); it!=_enumerationItems->end(); it++ ){
			string entry = (*it);
			enumerationItems.push_back(entry.c_str());
		}
	}
	doubleValue = _defaultDoubleValue;
	defaultDoubleValue = _defaultDoubleValue;
	AAL_DEBUG(logger, "Creating new DOUBLE property %s id %d values %d, %4.2f, %s",this->name.c_str(),this->id, this->getIntValue(), this->doubleValue, this->stringValue.c_str());
}

Property::Property(const char * _name, PROP_TYPE _type, const char * _defaultStringValue, vector<string> * _enumerationItems){
	setBasic(_name, _type);
	if(_enumerationItems){
		vector<string>::iterator it;
		for (it=_enumerationItems->begin(); it!=_enumerationItems->end(); it++ ){
			string entry = (*it);
			enumerationItems.push_back(entry.c_str());
		}
	}
	stringValue = _defaultStringValue;
	defaultStringValue = _defaultStringValue;
	AAL_DEBUG(logger, "Creating new OTHER property %s id %d values %d, %4.2f, %s",this->name.c_str(),this->id, this->getIntValue(), this->doubleValue, this->stringValue.c_str());
}

Property::~Property() {
	AAL_DEBUG(logger,"Destructor globalId: %d", this->id);
}

const char * Property::typeToString(){
	switch (this->type){
	case INTEGER:
		return "INTEGER";
		break;
	case DOUBLE:
		return "DOUBLE";
		break;
	case ENUMARATION:
		return "ENUMARATION";
		break;
	case ARGBCOLOR:
		return "ARGBCOLOR";
		break;
	default:
		return "STRING";
	}
}

void Property::setIntValue(int _intValue){
	this->intValue = _intValue;
}

const int Property::getIntValue(){
	return this->intValue;
}
